package io.renren.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.DateUtils;
import io.renren.dao.WxsendmbillDao;
import io.renren.dto.WxsendmbillDTO;
import io.renren.entity.WxsendmbillEntity;
import io.renren.entity.WxuserEntity;
import io.renren.service.WxsendmbillService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * ${comments}
 *
 * @author Sen 524227263@qq.com
 * @since 1.0.0 2024-06-11
 */
@Service
public class WxsendmbillServiceImpl extends CrudServiceImpl<WxsendmbillDao, WxsendmbillEntity, WxsendmbillDTO> implements WxsendmbillService {

    @Override
    public QueryWrapper<WxsendmbillEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<WxsendmbillEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public void addInfo(String traderMOID, String groupId, Integer type) {
        WxsendmbillEntity info = new WxsendmbillEntity();
        info.setSendmid(UUID.randomUUID().toString());
        info.setGroupid(groupId);
        info.setType(type);
        info.setSysCreated(new Date());
        info.setTradermoid(traderMOID);
        baseDao.insert(info);
    }

    @Override
    public Long getLasterSendStatus(String userId, Integer type, String groupId) {
        return baseDao.selectCount(new QueryWrapper<WxsendmbillEntity>()
                .eq("TraderMOID", userId)
                .eq("Type", type).eq("Groupid", groupId)
                .gt("SYS_Created", DateUtils.getSomeMinute(new Date(), -1)));
    }
}